package com.ym.manager.admin.ali;

import com.ym.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@RequestMapping("/ali/config")
@Controller
public class AliConfigInfoController {
    @Autowired
    private AliConfigInfoService aliConfigInfoService;

    @RequestMapping("/index")
    public String index(){

        return "ali/configIndex";
    }
    @ResponseBody
    @RequestMapping("/list")
    public String list(){
        List<AliConfigInfo> list = aliConfigInfoService.list();
        Map<String,Object> result = ResultUtil.result();
        result.put("data",list);
        return ResultUtil.toJSON(result);
    }

    @RequestMapping("/update/index")
    public String updateIdex(Model model,long id){
        AliConfigInfo aliConfigInfo = aliConfigInfoService.infoById(id);
        model.addAttribute("aliConfigInfo", aliConfigInfo);
        return "ali/update";
    }


    @ResponseBody
    @RequestMapping("/update")
    public String update(AliConfigInfo aliConfigInfo){
        Map<String,Object> result = ResultUtil.result();
        int i = aliConfigInfoService.update(aliConfigInfo);
        return ResultUtil.toJSON(result);
    }
}
